package com.wenkaihu.android.chess.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;

import com.wenkaihu.android.chess.socket.Server;
import com.wenkaihu.android.chess.view.SocketGoBang;

public class MyActivity extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Display defaultDisplay = this.getWindowManager().getDefaultDisplay();

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		final SocketGoBang view = new SocketGoBang(this, defaultDisplay);
		
		Handler handler = new Handler(){
			@Override
			public void handleMessage(Message msg) {
				view.checkAndRefresh();
				super.handleMessage(msg);
			}
		};
		
		Thread sThread = new Thread(new Server(view, handler));
		sThread.start();
		
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			Log.d("chess", "Get InterruptedException when sleep the thread!" + e);
		}
		
		setContentView(view);
	}
}